package io.renren.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import io.renren.common.utils.PageUtils;
import io.renren.dao.JxComputyDeviceDao;
import io.renren.entity.JxComputyDeviceEntity;
import io.renren.service.JxComputyDeviceService;
import io.renren.utils.Query;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;


@Service("jxComputyDeviceService")
public class JxComputyDeviceServiceImpl extends ServiceImpl<JxComputyDeviceDao, JxComputyDeviceEntity> implements JxComputyDeviceService {

    @Override
    public PageUtils queryPage(Map<String, Object> params) {
        IPage<JxComputyDeviceEntity> page = this.page(
                new Query<JxComputyDeviceEntity>().getPage(params),
                new QueryWrapper<JxComputyDeviceEntity>()
        );

        return new PageUtils(page);
    }

    @Override
    public PageUtils getAllWithPage(Map<String, Object> params) {
        PageHelper.startPage(Integer.parseInt(params.get("page").toString()),Integer.parseInt(params.get("limit").toString()));
        List<JxComputyDeviceEntity> list = this.baseMapper.getAllWithPage(params);
        setUseStatus(list);
        PageInfo<JxComputyDeviceEntity> pageInfo = new PageInfo<>(list);
        return new PageUtils(list,(int)pageInfo.getTotal(),pageInfo.getPageSize(),pageInfo.getPageNum());
    }

    /**
     * 设至使用状态
     * @param list
     */
    public void setUseStatus(List<JxComputyDeviceEntity> list){   //  设置使用状态
        for(JxComputyDeviceEntity entity:list){
            entity.setDeviceStatus("暂无使用");
        }
    }


    @Override
    public List<JxComputyDeviceEntity> getAllDevice(Map<String, Object> params) {
       return this.baseMapper.getAllWithPage(params);
    }

    @Override
    public Integer totalDevice(Long id) {
    return  this.baseMapper.totalDevice(id);
    }
}
